package com.fangcang.utils;

import java.io.UnsupportedEncodingException;

import org.apache.commons.codec.digest.DigestUtils;

public class Md5Util {

	public static String md5(String data) {
		if(null == data || "".equals(data)) {
			return "";
		}
		try {
			return new String(DigestUtils.md5(data.getBytes("UTF-8")), "UTF-8").toUpperCase();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return "";
		}
	}
	
	public static String md5(long timestamp, String partnerCode, String secureCode, String requestType) throws Exception {
		StringBuffer message = new StringBuffer();
		message.append(timestamp).append(partnerCode).append(com.fangcang.rest.Md5Util.md5Encode(secureCode).toUpperCase()).append(requestType);
		return com.fangcang.rest.Md5Util.md5Encode(message.toString()).toUpperCase();
	}
	
	public static void main(String[] args) throws Exception {
		
		System.out.println(com.fangcang.rest.Md5Util.md5Encode("secure_code_test").toUpperCase());
		System.out.println(md5(1509011923l, "P10000001", "secure_code_test", "getCityList"));
	}
}
